﻿namespace Game.Lib.CSG
{
    public class Ray
    {
        public Vector3 Start { get; set; }

        public Vector3 Direction
        {
            get
            {
                return _Dir;
            }
            set
            {
                Vector3 val = value;
                val.Normalize();
                _Dir = val;
            }
        }

        public float Length;

        private Vector3 _Dir;

        public Ray()
        {
            Start = Vector3.Zero;
            Direction = Vector3.XAxis;
            Length = 1f;
        }

        public Ray(Vector3 start, Vector3 end)
        {
            Start = start;
            Direction = end - start;
            Length = Vector3.Distance(start, end);
        }

        public Ray(Vector3 start, Vector3 dir, float len)
        {
            Start = start;
            Direction = dir;
            Length = len;
        }

        public Vector3 Get(float d)
        {
            return Start + d * Direction;
        }
    }
}
